import { Button, Tree } from 'antd';
import React, { useState } from 'react';

const { DirectoryTree } = Tree;

const Folder = (props) => {
  const { data, onNodeSelect, ...restProps } = props;

  const [selectedKeys, setSelectedKeys] = useState([]);

  const onSelect = (selecteKeys, { node }) => {
    if (selectedKeys.indexOf(node.key) !== -1) {
      setSelectedKeys([]);
      onNodeSelect({});
    } else {
      setSelectedKeys([node.key]);
      onNodeSelect(node);
    }
  };
  return (
    <DirectoryTree
      defaultExpandAll={true}
      treeData={data}
      selectedKeys={selectedKeys}
      onSelect={onSelect}
      {...restProps}
    />
  );
};

export default Folder;
